package com.jshoperxms.service.impl;

import com.jshoperxms.controller.mall.backstage.vo.basic.BasicRegionVo;
import com.jshoperxms.controller.utils.BaseTools;
import com.jshoperxms.controller.utils.DateTools;
import com.jshoperxms.controller.utils.json.GsonJson;
import com.jshoperxms.controller.utils.statickey.SerialKeys;
import com.jshoperxms.dao.BasicRegionTDao;
import com.jshoperxms.entity.BasicRegionT;
import com.jshoperxms.service.BasicRegionTService;
import org.hibernate.criterion.Criterion;
import org.hibernate.criterion.Restrictions;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

/**
 * Created by sdywcd on 17/1/1.
 * Des:
 */
@Service("basicRegionTService")
@Scope("prototype")
public class BasicRegionTServiceImpl extends BaseTServiceImpl<BasicRegionT> implements BasicRegionTService {


    @Resource
    private BasicRegionTDao basicRegionTDao;

    @Resource
    private Serial serial;

    @Override
    @Transactional(propagation= Propagation.REQUIRED)
    public void saveBasicRegionTransactional(BasicRegionT rq) {
        List<BasicRegionVo> list= GsonJson.parseJsonToData(rq.getName(),BasicRegionVo.class);
        for(BasicRegionVo b:list) {

            BasicRegionT bean = new BasicRegionT();
            bean.setId(this.serial.Serialid(SerialKeys.BASICREGIONT));
            bean.setCode(b.getCode());
            bean.setCreatetime(DateTools.getSystemTimeBi());
            bean.setCreatorid(BaseTools.getAdminCreateId());
            bean.setName(b.getName());
            bean.setParentid(rq.getParentid());
            bean.setParentname(rq.getParentname());
            bean.setPath(rq.getPath());
            bean.setSort(b.getSort());
            bean.setStatus(b.getStatus());
            bean.setType(rq.getType());
            bean.setUpdatetime(DateTools.getSystemTimeBi());
            bean.setVersiont(1);
            this.basicRegionTDao.save(bean);
        }

    }

}
